package api

import (

	"server/global"
    "server/model/common/response"
    "server/plugin/mall/model"
    "server/plugin/mall/model/request"
    "github.com/gin-gonic/gin"
    "go.uber.org/zap"
    "server/utils"
)

var A订单 = new(dingdan)

type dingdan struct {}

// CreateA订单 创建订单
// @Tags A订单
// @Summary 创建订单
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body model.A订单 true "创建订单"
// @Success 200 {object} response.Response{msg=string} "创建成功"
// @Router /dingdan/createA订单 [post]
func (a *dingdan) CreateA订单(c *gin.Context) {
	var info model.A订单
	err := c.ShouldBindJSON(&info)
	if err != nil {
		response.FailWithMessage(err.Error(), c)
		return
	}
    info.CreatedBy = utils.GetUserID(c)
	err = serviceA订单.CreateA订单(&info)
	if err != nil {
        global.GVA_LOG.Error("创建失败!", zap.Error(err))
		response.FailWithMessage("创建失败:" + err.Error(), c)
		return
	}
    response.OkWithMessage("创建成功", c)
}

// DeleteA订单 删除订单
// @Tags A订单
// @Summary 删除订单
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body model.A订单 true "删除订单"
// @Success 200 {object} response.Response{msg=string} "删除成功"
// @Router /dingdan/deleteA订单 [delete]
func (a *dingdan) DeleteA订单(c *gin.Context) {
	ID := c.Query("ID")
    userID := utils.GetUserID(c)
	err := serviceA订单.DeleteA订单(ID,userID)
	if err != nil {
        global.GVA_LOG.Error("删除失败!", zap.Error(err))
		response.FailWithMessage("删除失败:" + err.Error(), c)
		return
	}
    response.OkWithMessage("删除成功", c)
}

// DeleteA订单ByIds 批量删除订单
// @Tags A订单
// @Summary 批量删除订单
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Success 200 {object} response.Response{msg=string} "批量删除成功"
// @Router /dingdan/deleteA订单ByIds [delete]
func (a *dingdan) DeleteA订单ByIds(c *gin.Context) {
	IDs := c.QueryArray("IDs[]")
    userID := utils.GetUserID(c)
	err := serviceA订单.DeleteA订单ByIds(IDs,userID)
	if err != nil {
        global.GVA_LOG.Error("批量删除失败!", zap.Error(err))
		response.FailWithMessage("批量删除失败:" + err.Error(), c)
		return
	}
    response.OkWithMessage("批量删除成功", c)
}

// UpdateA订单 更新订单
// @Tags A订单
// @Summary 更新订单
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body model.A订单 true "更新订单"
// @Success 200 {object} response.Response{msg=string} "更新成功"
// @Router /dingdan/updateA订单 [put]
func (a *dingdan) UpdateA订单(c *gin.Context) {
	var info model.A订单
	err := c.ShouldBindJSON(&info)
	if err != nil {
		response.FailWithMessage(err.Error(), c)
		return
	}
    info.UpdatedBy = utils.GetUserID(c)
	err = serviceA订单.UpdateA订单(info)
    if err != nil {
        global.GVA_LOG.Error("更新失败!", zap.Error(err))
		response.FailWithMessage("更新失败:" + err.Error(), c)
		return
	}
    response.OkWithMessage("更新成功", c)
}

// FindA订单 用id查询订单
// @Tags A订单
// @Summary 用id查询订单
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data query model.A订单 true "用id查询订单"
// @Success 200 {object} response.Response{data=model.A订单,msg=string} "查询成功"
// @Router /dingdan/findA订单 [get]
func (a *dingdan) FindA订单(c *gin.Context) {
	ID := c.Query("ID")
	redingdan, err := serviceA订单.GetA订单(ID)
	if err != nil {
        global.GVA_LOG.Error("查询失败!", zap.Error(err))
		response.FailWithMessage("查询失败:" + err.Error(), c)
		return
	}
    response.OkWithData(redingdan, c)
}

// GetA订单List 分页获取订单列表
// @Tags A订单
// @Summary 分页获取订单列表
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data query request.A订单Search true "分页获取订单列表"
// @Success 200 {object} response.Response{data=response.PageResult,msg=string} "获取成功"
// @Router /dingdan/getA订单List [get]
func (a *dingdan) GetA订单List(c *gin.Context) {
	var pageInfo request.A订单Search
	err := c.ShouldBindQuery(&pageInfo)
	if err != nil {
		response.FailWithMessage(err.Error(), c)
		return
	}
	list, total, err := serviceA订单.GetA订单InfoList(pageInfo)
	if err != nil {
	    global.GVA_LOG.Error("获取失败!", zap.Error(err))
        response.FailWithMessage("获取失败:" + err.Error(), c)
        return
    }
    response.OkWithDetailed(response.PageResult{
        List:     list,
        Total:    total,
        Page:     pageInfo.Page,
        PageSize: pageInfo.PageSize,
    }, "获取成功", c)
}
// GetA订单DataSource 获取A订单的数据源
// @Tags A订单
// @Summary 获取A订单的数据源
// @accept application/json
// @Produce application/json
// @Success 200 {object} response.Response{data=object,msg=string} "查询成功"
// @Router /dingdan/getA订单DataSource [get]
func (a *dingdan) GetA订单DataSource(c *gin.Context) {
    // 此接口为获取数据源定义的数据
   dataSource, err := serviceA订单.GetA订单DataSource()
   if err != nil {
		global.GVA_LOG.Error("查询失败!", zap.Error(err))
        response.FailWithMessage("查询失败:" + err.Error(), c)
		return
   }
    response.OkWithData(dataSource, c)
}
// GetA订单Public 不需要鉴权的订单接口
// @Tags A订单
// @Summary 不需要鉴权的订单接口
// @accept application/json
// @Produce application/json
// @Param data query request.A订单Search true "分页获取订单列表"
// @Success 200 {object} response.Response{data=object,msg=string} "获取成功"
// @Router /dingdan/getA订单Public [get]
func (a *dingdan) GetA订单Public(c *gin.Context) {
    // 此接口不需要鉴权 示例为返回了一个固定的消息接口，一般本接口用于C端服务，需要自己实现业务逻辑
    serviceA订单.GetA订单Public()
    response.OkWithDetailed(gin.H{"info": "不需要鉴权的订单接口信息"}, "获取成功", c)
}
